﻿using System;
using System.Data;
using System.Data.SqlClient;
using PPI.Data;

namespace PPI.Data.Inspection
{
    public class DInspectionMap
    {
        public static DataSet SelectAll(string connectionKey)
        {
            SqlDataAdapter da = null;
            try
            {
                da = new SqlDataAdapter("up_Inspection_Map_SelectAll", DBHelper.GetConnection(connectionKey));
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                DataSet ds = new DataSet();
                da.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                throw new Exception("Error executing up_Inspection_Map_SelectAll", ex);
            }
            finally
            {
                if (da != null) da.SelectCommand.Connection.Close();
            }
        }

        public static DataSet SelectSectionsAll(string connectionKey)
        {
            try
            {
                DataSet dsSections = new DataSet("DS_Sections");
                DataTable dtSections = new DataTable("tb_Sections");

                dtSections.Columns.Add(new DataColumn("idSection", typeof (Int32)));
                dtSections.Columns.Add(new DataColumn("Name", typeof(String)));

                for (int i = 1; i < 37; i++) 
                {
                    DataRow drSection = dtSections.NewRow();

                    drSection["idSection"] = i;
                    drSection["Name"] = i.ToString();

                    dtSections.Rows.Add(drSection);
                }

                return dsSections;
            }
            catch (Exception ex)
            {
                throw new Exception("Error executing up_Inspection_Map_SelectAll", ex);
            }
        }
    }
}
